<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <rx-layout>
            <div slot="center">
                <a-form-model ref="form" :model="mdl" :rules="rules">
                    <a-row :span="24">
                        <a-col :span="24">
                            <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" prop="bpmAdminGroupKey">
                                <rx-input-button v-model="mdl.bpmAdminGroupKey" @click="selectGroups"></rx-input-button>
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                </a-form-model>
            </div>
        </rx-layout>
    </rx-dialog>
</template>
<script>
import OsInstApi from '@/api/user/org/osInst'
import {BaseFormModel, RxDialog, RxLayout,RxInputButton,Dialog} from "@lowcode/jpaas-common-lib";

export default {
    name: 'OsInstSetBpmAdminGroup',
    mixins: [BaseFormModel],
    components: {
        RxDialog,
        RxLayout,
        RxInputButton
    },
    methods: {
        selectGroups(vm) {
            var conf = {
                curVm: this,
                data: {single: true, showDimId: true, tenantId: this.pkId},
                widthHeight: ['900px', '700px']
            };
          if (this.mdl.bpmAdminGroupKey) {
            let group=JSON.parse(this.mdl.bpmAdminGroupKey);
            //初始化用户组信息
            conf.data["initGroups"]=[{name:this.$comi18('form.haveSelectGroup', '上次已选择的用户组'),key:'0',data:[{"key":group.value,"name":group.text}]}]
          }
            Dialog.openGroupDialog(conf, function (self, group) {
                vm.setVal(group.key, group.name);
            })
        },
        get(id) {
            return OsInstApi.get(id);
        },
        onload_(data){
            if(data) {
                if (data.bpmAdminGroupKey) {
                    data.bpmAdminGroupKey = JSON.stringify({
                        text: data.bpmAdminGroupName,
                        value: data.bpmAdminGroupKey
                    });
                }
            }
        },
        save(values) {
            if(values.bpmAdminGroupKey){
                let json=JSON.parse(values.bpmAdminGroupKey);
                values.bpmAdminGroupKey=json.value;
                values.bpmAdminGroupName=json.text;
            }else{
                values.bpmAdminGroupName="";
            }
            return OsInstApi.save(values);
        }
    }
}
</script>
